<?php 
    $is_administrator = $_SESSION['isAdministrator'];
    $listSubSite = Configure::read('App.themes.listSubSite');   
    $sub_site = null;     
    if((isset($this->request->query['sub_site']))&&(!empty($this->request->query['sub_site']))){
        $sub_site =intval($this->request->query['sub_site']);        
    }    
    $_listSubSite = array();
    $sub_site_default = key($listSubSite);     
    if(!$is_administrator){
        $_listSubSite = $_SESSION['_listSubSite'];        
        if(empty($_listSubSite)){
            $conds = array('NodeType.sub_site'=>-1,'NodeType.enabled'=>1);
        }else{$conds = array('NodeType.sub_site'=>$_listSubSite,'NodeType.enabled'=>1);}                        
    }else{
        if(!empty($sub_site)){$sub_site_default = $sub_site;}
        //debug($sub_site_default);exit;
        $conds  = array('NodeType.sub_site'=>$sub_site_default,'NodeType.enabled'=>1);
    }       
        $left_menu = ClassRegistry::init('Node.NodeType')->find('all',array(                
            'conditions'=>$conds        
        ));                 
?>
<div id="sidebar">
    <a href="#" class="visible-phone"><i class="icon icon-home"></i> <?php echo __d('system','Dashboard');?></a>
    <ul>        
            <li class="active submenu open">
            <a href="index.html"><i class="icon-pencil"></i> <span><?php echo __d('system','Content Management');?></span></a>
            <?php if(!empty($left_menu)):?>        
                <ul> 
                    <?php $class = '';foreach($left_menu as $key=>$value):?>
                    <?php if(!empty($value['Term'])){$class = 'wd-hover';}?>                               
                        <li class="<?php echo $class;?>">
                            <a href="<?php echo $this->Html->url(array('plugin'=>'node','controller'=>'node','action'=>'admin_list_index',$value['NodeType']['id'],'?'=>array('sub_site'=>$sub_site)));?>"><?php echo __d('system',$value['NodeType']['name']);?></a>
                                <?php if(!empty($value['Term'])):?>
                                    <ul class="wd-sub-hover">
                                        <?php foreach($value['Term'] as $term_id=>$term_name):?>                                       
                                            <li><a href="<?php echo $this->Html->url(array('plugin'=>'node','controller'=>'node','action'=>'admin_list_index',$value['NodeType']['id'],$term_name['id'],'?'=>array('sub_site'=>$sub_site)));?>"><?php echo $term_name['name'];?></a></li>                                    
                                        <?php endforeach;?>
                                    </ul>
                                <?php endif;$class = '';?>
                        </li>                
                    <?php endforeach;?>                    
                </ul>            
            <?php endif;?>
        </li>                        
        <!--<li class="submenu"><a href="#"><i class="icon-book"></i> <span>Menu</span></a></li>-->
        <?php if($is_administrator):?>
        <li class="submenu">
            <a href="#"><i class="icon-user"></i> <span><?php echo __d('system','Users');?></span></a>
            <ul>
                <li><a href="<?php echo $this->Html->url(array('plugin'=>'user','controller'=>'user','?'=>array('sub_site'=>$sub_site)));?>"><?php echo __d('system','User');?></a></li>
                <li><a href="<?php echo $this->Html->url(array('plugin'=>'user','controller'=>'roles','?'=>array('sub_site'=>$sub_site)));?>"><?php echo __d('system','Role');?></a></li>
                <li><a href="<?php echo $this->Html->url(array('plugin'=>'user','controller'=>'permissions','?'=>array('sub_site'=>$sub_site)));?>"><?php echo __d('system','Permision');?></a></li>
            </ul>
        </li>
        <?php endif;?>
        <?php if($is_administrator):?>
            <li class="submenu">
            <a href="#"><i class="icon-folder-open"></i> <span><?php echo __d('system','Member Site');?></span></a>
            <?php $listSubsite = Configure::read('App.themes.listSubSite');?>
            <?php if(!empty($listSubsite)):
                  unset($listSubsite[1]); 
            ?>
                <ul>
                    <?php if(!empty($listSubsite)):?>
                        <?php foreach($listSubsite as $k=>$v):?>
                            <li><a href="/admin/?sub_site=<?php echo $k;?>" target="_blank"><?php echo __d('system',$v);?></a></li>                
                        <?php endforeach;?>
                    <?php endif;?>
                </ul>
            <?php endif;?>
        </li>
        <?php endif;?>
        <?php if($is_administrator):?>
        <li class="submenu">
            <a href="#"><i class="icon-folder-open"></i> <span><?php echo __d('system','Config System');?></span></a>
            <ul>
                <li><a href="<?php echo $this->Html->url(array('plugin'=>'node','controller'=>'node','action'=>'admin_management_subsite','?'=>array('sub_site'=>$sub_site)))?>"><?php echo __d('system','Subsite');?></a></li>
                <li><a href="<?php echo $this->Html->url(array('plugin'=>'node','controller'=>'node','action'=>'admin_management_language','?'=>array('sub_site'=>$sub_site)))?>"><?php echo __d('system','Language');?></a></li>
                <li><a href="<?php echo $this->Html->url(array('plugin'=>'node','controller'=>'node','action'=>'manage_config_mail','?'=>array('sub_site'=>$sub_site)))?>"><?php echo __d('system','Mail');?></a></li>
                <li><a href="<?php echo $this->Html->url(array('plugin'=>'node','controller'=>'node','action'=>'admin_config_action','?'=>array('sub_site'=>$sub_site)))?>"><?php echo __d('system','Action');?></a></li>
                <li><a href="<?php echo $this->Html->url(array('plugin'=>'node','controller'=>'node_types','?'=>array('sub_site'=>$sub_site)))?>"><?php echo __d('system','NodeType');?></a></li>
                <li><a href="<?php echo $this->Html->url(array('plugin'=>'block','controller'=>'block','?'=>array('sub_site'=>$sub_site)))?>"><?php echo __d('system','Block');?></a></li>
            </ul>
        </li>
        <?php endif;?>
    </ul>
</div>